#!/usr/bin/env python

import subprocess

def pkg2dsc(pkg):
    ifile = subprocess.Popen(['apt-cache', 'show', pkg],
                         stdout=subprocess.PIPE).stdout

    res = '=== %s ===\n' % pkg
    res += '{{{\n'

    for line in ifile:
        if line.startswith('Description:'):
            res += line
            break

    for line in ifile:
        if line[0] == ' ':
            res += line
        else:
            break
    res += '}}}\n'

    return res

def main():
    ifile = file('packages.dat')
    packages = ifile.read().split()
    ifile.close()

    ofile = file('../wiki/packages.wiki', 'w')
    ofile.write('#labels Featured\n')
    for x in packages:
        ofile.write(pkg2dsc(x))
    ofile.close()

if __name__ == '__main__':
    main()
